home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / mtools-3.000 / mtools-3 / mtools-3.0 / fat_free.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-30  |  748 b   |  35 lines

  1. #include "sysincludes.h"
  2. #include "msdos.h"
  3. #include "fsP.h"
  4.  
  5. /*
  6.  * Remove a string of FAT entries (delete the file).  The argument is
  7.  * the beginning of the string.  Does not consider the file length, so
  8.  * if FAT is corrupted, watch out!
  9.  */
  10.  
  11. int fat_free(Stream_t *Stream, unsigned int fat)
  12. {
  13.     DeclareThis(Fs_t);
  14.     unsigned int next;
  15.                     /* a zero length file? */
  16.     if (fat == 0)
  17.         return(0);
  18.  
  19.     /* CONSTCOND */
  20.     while (1) {
  21.                     /* get next cluster number */
  22.         next = This->fat_decode(This,fat);
  23.         /* mark current cluster as empty */
  24.         if (This->fat_encode(This,fat, 0) || next == 1) {
  25.             fprintf(stderr, "fat_free: FAT problem\n");
  26.             This->fat_error++;
  27.             return(-1);
  28.         }
  29.         if (next >= This->last_fat)
  30.             break;
  31.         fat = next;
  32.     }
  33.     return(0);
  34. }
  35.